import os
import time
import binascii
from datetime import datetime, timedelta
import socket


def create_id():
    id = '%s-%s' % (time.strftime('%Y%m%d-%H%M%S'), binascii.hexlify(os.urandom(2)).decode())

    return id


def datetime_8():
    # 将 UTC 时间转换为北京时间存储到数据库
    datetime_add_8 = datetime.utcnow() + timedelta(hours=8)
    return datetime_add_8


def get_ip_address():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))

    ip = s.getsockname()[0]

    s.close()

    return ip